<?php

/**
 * Created by IntelliJ IDEA.
 * User: keke
 * Date: 18-10-28
 * Time: 下午2:58
 */
require_once "../congfig/config.php";
require_once "../lib/common.php";
$pid = $_POST['pid'];
$username = $_POST['username'];
if ($username == null) {
    exit(jsoncall(-1, "信息不能为空"));
}
$sql = "SELECT * FROM `users` WHERE username = '$username' ";
$query = $conn->query($sql);
if ($query) {
    $relsut = $query->fetch_array();
    $uid = $relsut['uid'];
    $sql = "SELECT * FROM `puser` WHERE uid='$uid'and pid='$pid' ";
    $query = $conn->query($sql);
    $num = $query->num_rows;
    if ($num >= 1) {
        exit(jsoncall(-1, "已存在该用户"));
    }
    $sql = "INSERT INTO puser VALUES (null ,'$uid','$pid')";
    $query = $conn->query($sql);
    if ($query) {
        exit(jsoncall(1, "添加项目成员成功"));
    } else {
        exit(jsoncall(-1, "添加项目成员失败"));
    }
} else {
    exit(jsoncall(-1, "不存在该用户"));
}
// $sql = "SELECT * FROM `puser` WHERE uid='$uid'and pid='$pid' ";
// $query = $conn->query($sql);
// $num = $query->num_rows;
// if ($num >= 1) {
//     exit(jsoncall(-1, "已存在该用户"));
// }
// $sql = "INSERT INTO puser VALUES (null ,'$uid','$pid')";
// $query = $conn->query($sql);
// if ($query) {
//     exit(jsoncall(1, "添加项目成员成功"));
// } else {
//     exit(jsoncall(-1, "添加项目成员失败"));
// }